/*   1:    */ package tt.dz.web.controller.user;
/*   2:    */ 
/*   3:    */ import com.alibaba.fastjson.JSON;
/*   4:    */ import java.util.ArrayList;
/*   5:    */ import java.util.LinkedHashMap;
/*   6:    */ import java.util.List;
/*   7:    */ import javax.annotation.Resource;
/*   8:    */ import javax.servlet.http.HttpServletRequest;
/*   9:    */ import javax.servlet.http.HttpServletResponse;
/*  10:    */ import org.apache.commons.lang3.StringUtils;
/*  11:    */ import org.springframework.beans.factory.annotation.Autowired;
/*  12:    */ import org.springframework.beans.factory.annotation.Qualifier;
/*  13:    */ import org.springframework.stereotype.Controller;
/*  14:    */ import org.springframework.web.bind.annotation.RequestMapping;
/*  15:    */ import org.springframework.web.bind.annotation.ResponseBody;
/*  16:    */ import tt.dz.biz.service.cardno.CardNoBuilder;
/*  17:    */ import tt.dz.biz.service.cardno.CardNoDirector;
/*  18:    */ import tt.dz.biz.service.cardno.CardNoProduct;
/*  19:    */ import tt.dz.biz.service.cardno.DefaulCardNoDirector;
/*  20:    */ import tt.dz.biz.service.cardno.DefaultCardNoBuilder;
/*  21:    */ import tt.dz.biz.service.cardno.DefaultCardNoCardConfigSequenceGenerator;
/*  22:    */ import tt.dz.biz.service.financial.MerchantService;
/*  23:    */ import tt.dz.biz.service.user.IdentityAccountService;
import tt.dz.common.DzConstants;
/*  24:    */ import tt.dz.common.DzConstants.CardBIN;
/*  25:    */ import tt.dz.common.DzConstants.CardType;
/*  26:    */ import tt.dz.common.ExcelUtill;
/*  27:    */ import tt.dz.common.LogUtil;
/*  28:    */ import tt.dz.vo.IdentityAccountVO;
/*  29:    */ import tt.dz.vo.MerchantVO;
/*  30:    */ import tt.dz.vo.ResponseModle;
/*  31:    */ import tt.dz.web.controller.BaseController;
/*  32:    */ 
/*  33:    */ @Controller
/*  34:    */ public class IdentityAccountController
/*  35:    */   extends BaseController
/*  36:    */ {
/*  37:    */   @Resource(name="identityAccountService")
/*  38:    */   private IdentityAccountService identityAccountService;
/*  39:    */   @Autowired
/*  40:    */   @Qualifier("merchantService")
/*  41:    */   private MerchantService merchantService;
/*  42:    */   
/*  43:    */   @RequestMapping(value={"/batchCreateIdentityAccount"}, produces={"application/json;charset=UTF-8"})
/*  44:    */   @ResponseBody
/*  45:    */   public String batchCreateIdentityAccount(HttpServletRequest request, HttpServletResponse response)
/*  46:    */   {
/*  47: 52 */     int createdAmountSuccess = 0;
/*  48:    */     try
/*  49:    */     {
/*  50: 54 */       String merchantCode = request.getParameter("merchantCode");
/*  51: 55 */       MerchantVO merchantVO = this.merchantService.queryMerchantByCode(merchantCode);
/*  52: 56 */       String companyCode = request.getParameter("companyCode");
/*  53: 57 */       String areaCode = request.getParameter("areaCode");
/*  54: 58 */       Integer createAmount = Integer.valueOf(Integer.parseInt(request.getParameter("createAmount")));
/*  55:    */       
/*  56: 60 */       areaCode = StringUtils.isBlank(areaCode) ? "0028" : areaCode.trim();
/*  57:    */       
/*  58:    */ 
/*  59: 63 */       DzConstants.CardType cardType = DzConstants.CardType.IDENTITY_CARD;
/*  60: 64 */       DzConstants.CardBIN cardBIN = DzConstants.CardBIN.CARDBIN_188;
/*  61: 65 */       CardNoBuilder cardNoBuilder = new DefaultCardNoBuilder();
/*  62: 66 */       DefaultCardNoCardConfigSequenceGenerator cardNoSequenceGenerator = new DefaultCardNoCardConfigSequenceGenerator();
/*  63: 67 */       cardNoSequenceGenerator.setCardType(cardType);
/*  64: 68 */       cardNoSequenceGenerator.setCardBin(cardBIN);
/*  65: 69 */       cardNoSequenceGenerator.setMerchant(merchantVO);
/*  66: 70 */       cardNoSequenceGenerator.setAreaCode(areaCode);
/*  67: 71 */       CardNoDirector director = new DefaulCardNoDirector(cardType.value(), cardBIN.value(), merchantCode, areaCode, cardNoSequenceGenerator);
/*  68: 72 */       director.setBuilder(cardNoBuilder);
/*  69: 73 */       CardNoProduct[] cardNoProducts = director.product(createAmount.intValue());
/*  70: 74 */       boolean excuteFlag = false;
/*  71: 75 */       for (CardNoProduct cardNoProduct : cardNoProducts)
/*  72:    */       {
/*  73: 76 */         excuteFlag = this.identityAccountService.createIdentityAccount(cardNoProduct, companyCode);
/*  74: 77 */         createdAmountSuccess += (excuteFlag ? 1 : 0);
/*  75:    */       }
/*  76:    */     }
/*  77:    */     catch (Exception e)
/*  78:    */     {
/*  79: 80 */       LogUtil.error("批量建立身份验证卡及关联用户出现异常", e);
/*  80:    */     }
/*  81: 82 */     return JSON.toJSONString(assemblyResponseData(true, Integer.valueOf(createdAmountSuccess)));
/*  82:    */   }
/*  83:    */   
/*  84:    */   @RequestMapping(value={"/listAllIdentityAccount"}, produces={"application/json;charset=UTF-8"})
/*  85:    */   @ResponseBody
/*  86:    */   public String listAllIdentityAccount()
/*  87:    */   {
/*  88: 92 */     ResponseModle responseModle = null;
/*  89:    */     try
/*  90:    */     {
/*  91: 94 */       List<IdentityAccountVO> identityAccountList = this.identityAccountService.listAllIdentityAccount();
/*  92: 95 */       responseModle = new ResponseModle("success", identityAccountList);
/*  93:    */     }
/*  94:    */     catch (Exception e)
/*  95:    */     {
/*  96: 97 */       LogUtil.error("查询所有身份验证卡异常", e);
/*  97: 98 */       responseModle = new ResponseModle("error", new ArrayList());
/*  98:    */     }
/*  99:100 */     return JSON.toJSONString(responseModle);
/* 100:    */   }
/* 101:    */   
/* 102:    */   @RequestMapping(value={"/queryIdentityAccount"}, produces={"application/json;charset=UTF-8"})
/* 103:    */   @ResponseBody
/* 104:    */   public String queryIdentityAccount(HttpServletRequest request)
/* 105:    */   {
/* 106:111 */     ResponseModle responseModle = null;
/* 107:    */     try
/* 108:    */     {
/* 109:113 */       IdentityAccountVO identityAccountVO = (IdentityAccountVO)JSON.parseObject(request.getParameter("identityAccountVO"), IdentityAccountVO.class);
/* 110:    */       
/* 111:    */ 
/* 112:116 */       List<IdentityAccountVO> identityAccountList = this.identityAccountService.queryIdentityAccount(identityAccountVO);
/* 113:117 */       responseModle = new ResponseModle("success", identityAccountList);
/* 114:    */     }
/* 115:    */     catch (Exception e)
/* 116:    */     {
/* 117:119 */       LogUtil.error("根据传入条件查询身份验证卡异常", e);
/* 118:120 */       responseModle = new ResponseModle("error", new ArrayList());
/* 119:    */     }
/* 120:122 */     return JSON.toJSONString(responseModle);
/* 121:    */   }
/* 122:    */   
/* 123:    */   @RequestMapping({"/exportIdentityAccount"})
/* 124:    */   @ResponseBody
/* 125:    */   public byte[] exportIdentityAccount(HttpServletRequest request, HttpServletResponse response)
/* 126:    */   {
/* 127:134 */     byte[] b = null;
/* 128:    */     try
/* 129:    */     {
/* 130:136 */       IdentityAccountVO identityAccountVO = (IdentityAccountVO)JSON.parseObject(request.getParameter("identityAccountVO"), IdentityAccountVO.class);
/* 131:    */       
/* 132:138 */       List<IdentityAccountVO> identityAccountList = this.identityAccountService.queryIdentityAccountAndConvert(identityAccountVO);
/* 133:139 */       LinkedHashMap<String, String> fieldMap = new LinkedHashMap();
/* 134:140 */       fieldMap.put("卡号", "cardNo");
/* 135:141 */       fieldMap.put("密码", "password");
/* 136:142 */       fieldMap.put("状态", "stateDesc");
/* 137:143 */       fieldMap.put("所属企业", "enterpriseName");
/* 138:144 */       fieldMap.put("所属运营商", "merchantdesc");
/* 139:    */       
/* 140:146 */       b = ExcelUtill.getCSVByteArray("身份认证卡报表", fieldMap, identityAccountList);
/* 141:    */       
/* 142:148 */       response.setHeader("Content-Disposition", "attachment;fileName=demo.csv");
/* 143:149 */       response.setHeader("Content-Transfer-Encoding", "binary");
/* 144:150 */       response.setContentType("application/vnd.ms-excel; charset=utf-8");
/* 145:    */     }
/* 146:    */     catch (Exception e)
/* 147:    */     {
/* 148:152 */       LogUtil.error("根据传入条件查询身份验证卡并导出excel异常", e);
/* 149:    */     }
/* 150:154 */     return b;
/* 151:    */   }
/* 152:    */   
/* 153:    */   @RequestMapping(value={"/bacthUpdateIdentityAccount"}, produces={"application/json;charset=UTF-8"})
/* 154:    */   @ResponseBody
/* 155:    */   public String bacthUpdateIdentityAccount(HttpServletRequest request)
/* 156:    */   {
/* 157:165 */     boolean excuteFlag = false;
/* 158:    */     try
/* 159:    */     {
/* 160:167 */       List<IdentityAccountVO> identityAccountList = JSON.parseArray(request.getParameter("modifyList"), IdentityAccountVO.class);
/* 161:    */       
/* 162:169 */       excuteFlag = this.identityAccountService.bacthUpdateIdentityAccount(identityAccountList);
/* 163:    */     }
/* 164:    */     catch (Exception e)
/* 165:    */     {
/* 166:172 */       LogUtil.error(" 批量更新身份识别卡对象异常", e);
/* 167:    */     }
/* 168:174 */     return JSON.toJSONString(assemblyResponseData(excuteFlag, null));
/* 169:    */   }
/* 170:    */ }


/* Location:           F:\work\pengyu\mainServer\WEB-INF\classes\
 * Qualified Name:     tt.dz.web.controller.user.IdentityAccountController
 * JD-Core Version:    0.7.0.1
 */